1. Field of the Invention
This invention is a method and apparatus for updating computer program code stored in nonvolatile memory, in a way that that reduces the chance of corrupting the part of the code used for initialization.
2. Description of Related Art
Referring to FIG. 1, a unit that contains a general processor, such as a computer system 106 or an adapter 100, requires code to initialize (boot). Because the processor 114 or 130 in such a unit must be able to access boot code 116 using basic hardware access, the boot code 116 must be stored in nonvolatile memory 118. Nonvolatile memory, includes, but is not limited to, Read-Only Memory (ROM), Electrically Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory, and the like. Flash memory is the nonvolatile memory of choice in many modern applications. However, unlike conventional RAM, whose data can be simply read or written, flash memory is setup to be read-only during normal operations and requires special procedures to be written.
In the example of an adapter, when a unit is booted, the processor 114 is directed to a particular address in the nonvolatile memory 118, where it begins executing boot code 116 in boot region 122. It is important that this boot code 116 run correctly, otherwise the unit 100 will not initialize correctly and basic operations will fail. Moreover, a host computer system 106 containing this unit may in turn fail to boot. For example, if the boot operations fail in a device located in the host computer system 106, the entire computer system may fail to boot. Thus, care is required in updating the boot code.
Although the above discussion describes how the processor 114 in a unit 100 such as a HBA (Host Bus Adapter) uses nonvolatile memory for initialization, the processor 130 in the host computer system 106 also utilizes nonvolatile memory in a similar fashion. For reliability, the nonvolatile memory of the host computer system 106 may similarly be divided into boot code and application code. The boot code is executed when the host computer system 106 is first turned on to initialize the host computer system 106, and the application code is run in order to read a mass storage device, such as a disk drive. Then the operating system code that is stored on the disk can be loaded and run. One program that is typically stored in nonvolatile memory of a host computer is the Basic Input/Output System (BIOS).
In order to support new technology or to correct problems, it may become necessary or desirable to update the code in nonvolatile memory. If the nonvolatile memory is flash memory, then a program can be run in situ to update the BIOS used by the host computer or to update the code stored in an adapter. This saves the expense of removing the nonvolatile memory from the unit and updating it with specialized equipment, usually at the manufacturer's site.
When a program is used to update nonvolatile memory, care must be taken to handle the varied environments at customer sites. For example, with some flash memory, an entire block of memory must be erased before writing can commence. If the erase operation is successful, then write operations can proceed, often one byte at a time. Once a block is erased, it cannot be reverted and a new block of code must be successfully written in its place. As each byte is written, it should be checked to verify that the code was written correctly. If a problem is detected, the write operation may be re-tried several times. Once an entire block is written, the entire block may be verified byte-by-byte. A checksum or a cyclic redundancy check (CRC) may also be performed to validate the code being written.
On occasion, problems with updating nonvolatile memory can arise. For example, loss of power would prematurely terminate update operations. If an adapter was reset while being updated, the bus mapping of the adapter could change and writes to the nonvolatile memory could fail. Another source of problems is PCI bus version incompatibility. For example, when updating an adapter in a host system that is not PCI 2.1 compliant, the REQ64 and ACK64 bus signals may be left floating. As a result, incorrect addresses may be used in updating the adapter's nonvolatile memory and the code written to nonvolatile memory can be corrupted.
If the boot code is corrupted but the unit is currently using the application code, the unit will not immediately be affected by the error. However, the error will cause problems the next time the boot code is utilized, at the next power-up or when the unit is reset. For example, in the case of corrupt boot code in an adapter attached to the PCI bus of a host computer, when the host computer is powered up, its BIOS will identify and communicate with every adapter in its PCI bus. If an adapter fails its boot operations, either the adapter will be skipped by the host system or it may cause the host system's BIOS to fail. Because the host computer cannot identify or communicate with the adapter, it cannot update the nonvolatile memory in the adapter. Thus, the only recourse at that time is to send the adapter back to the manufacturer.
To avoid corruption of the nonvolatile memory, some units divide the nonvolatile memory code into regions so that each update-code file contains just one region such as the boot code region or the application code region, or combinations thereof. With multiple update files, a user can pick and choose which regions of memory to update without having to update the entire nonvolatile memory. In addition, the user may be prohibited from updating certain areas of memory. For example, only the application firmware might be placed in an update-code file and made available to a user. If the user performs an update with that update-code file, only the application region would be updated, leaving the boot region intact. Without this fragmentation and restriction of the update-code files, a user believing that “more is better” may choose to update all the regions or unnecessary regions, increasing the likelihood of updating errors. Other manufacturers suggest avoiding updating the boot code in their documentation.
In any case, because the image file selection process is manually performed, if the user is given a menu of available image files for updating, there is no mechanism for preventing a user from updating vital regions that do not need updating. Even when it is necessary to update the boot code region, current solutions do not first test the ability to write in a non-vital region, nor do they warn the user that an update is unnecessary or regressive.
Thus, a need exists for an apparatus and method for updating nonvolatile memory that warns the user that an update is unnecessary or regressive, and also tests the ability to write in a non-vital region prior to updating a vital region.